<template>
    <div class="myCollect">
        <x-header :left-options="{showBack: true,backText:'我的收藏'}" class="headerBox"></x-header>
        <!-- tab -->
        <tab
                v-model="tabIndex"
                default-color="#686868"
                active-color="#000"
                custom-bar-width="20px"
                bar-active-color="#1F7AFF"
        >
            <tab-item selected>课程</tab-item>
            <tab-item>资料</tab-item>
        </tab>
        <swiper
                v-model="tabIndex"
                :show-dots="false"
                ref="cateSwiper"
                :min-moving-distance="2000"
                @on-get-height="getPageHeight"
        >
            <swiper-item v-for="(item, index) in listContent" :key="index">
                <!-- 课程 -->
                <div v-if="item.title == '课程'" class="courseBox">
                    <div class="search" style="display: none">
                        <icon type="search" size="15"/>
                        <input type="text" placeholder="输入相关信息" auto-focus class="input"/>
                        <span @click="onFilterCourse()">筛选</span>
                    </div>
                    <!-- 筛选菜单 -->
                    <div class='filterMask' v-if="courseMask"></div>
                    <div class='popFilter' v-if="courseFilter" >
                        <div class='filterTitle'>课程筛选</div>
                        <div class='filterLabels'>
                            <div class='filterLabel' v-for="(label, indexl) in item.courseLabels" :key="indexl">
                                {{label.label}}
                            </div>
                        </div>
                    </div>


                    <div v-for="(collect, indexc) in courseList" :key="indexc" class="courseList">
                        <router-link :to="{name:'courseDetails-noBuy',query:{id:collect.courseId}}" class="itemBox">
                            <swipeout>
                                <swipeout-item transition-mode="follow">
                                    <div slot="right-menu">
                                        <swipeout-button class="delBtn">删除</swipeout-button>
                                        <swipeout-button class="shareBtn">分享</swipeout-button>
                                    </div>

                                    <div slot="content" class="courses">
                                        <div class="leftCont">
                                            <img :src="collect.largePicture" class="courseImg"/>
                                        </div>
                                        <div class="rightCont">
                                            <div class="contTitle">{{collect.title}}</div>
                                            <div class="orderInfo">{{collect.lessonNum}}课时 | {{collect.userNum}}学过</div>
                                            <div class="price">
                                                ￥{{collect.price/100}}
                                                <span>（会员免费）</span>
                                            </div>
                                        </div>
                                    </div>
                                </swipeout-item>
                            </swipeout>
                        </router-link>
                    </div>
                </div>
                <!-- 资料 -->
                <div v-if="item.title == '资料'" class="dataBox">
                    <div class="search" style="border-bottom: 10px solid #f8f9fa;display: none">
                        <icon type="search" size="15"/>
                        <input type="text" placeholder="输入相关信息" auto-focus class="input"/>
                        <span @click="onFilterData()">筛选</span>
                    </div>
                    <!-- 筛选菜单 -->
                    <div class='filterMask' v-if="dataMask"></div>
                    <div class='popFilter' v-if="dataFilter">
                        <div class='filterTitle'>资料筛选</div>
                        <div class='filterLabels'>
                            <div class='filterLabel' v-for="(label, indexdl) in item.dataLabels" :key="indexdl">
                                {{label.label}}
                            </div>
                        </div>
                    </div>

                    <img src='../assets/images/nullmaterial04.png' class="emptyBox" v-if="item.dataList.length <= 0"/>

                    <div class='dataList' v-for="(data, indexd) in materialsList" :key="indexd">
                        <div class='dataLeft'>
                            <img src='../assets/images/material01.png'/>
                            <div class='dataInfo'>
                                <div>{{data.title}}</div>
                                <div>{{data.date}}<span class='ml_20'>
                                </span><span class='ml_20'>上传:{{data.nickName}}</span>
                                </div>
                            </div>
                        </div>
                        <div class='dataRight'>
                            <img src='../assets/images/material11.png'/>
                            <img src='../assets/images/material07.png'/>
                            <img src='../assets/images/material08.png'/>
                        </div>
                    </div>
                </div>
            </swiper-item>
        </swiper>
    </div>
</template>

<script>
    import {XHeader, Tab, TabItem, Swiper, SwiperItem, Icon, Swipeout, SwipeoutItem, SwipeoutButton} from "vux";
    import {MyCollect,MyMaterial} from '@/api/index/study';
    import store from "../store/store";

    export default {
        components: {
            XHeader,
            Tab,
            TabItem,
            Swiper,
            SwiperItem,
            Icon,
            Swipeout,
            SwipeoutItem,
            SwipeoutButton
        },
        data() {
            return {
                tabIndex: 0,
                // tab内容
                courseList: [],
                materialsList:[],
                listContent: [
                    {
                        title: "课程",
                        courseLabels: [
                            {
                                label: '学习中'
                            },
                            {
                                label: '已完成'
                            },
                            {
                                label: '已购买'
                            },
                            {
                                label: '未购买'
                            }
                        ],
                        collects: [
                            {
                                courseImg: require("../assets/images/course01.png"),
                                courseName: "英语零基础直达大学四级",
                                periods: "36",
                                number: "1210",
                                price: "399"
                            },
                            {
                                courseImg: require("../assets/images/course01.png"),
                                courseName: "英语零基础直达大学四级",
                                periods: "36",
                                number: "1210",
                                price: "399"
                            }
                        ],
                    },
                    {
                        title: "资料",
                        dataLabels: [
                            {
                                label: '图片'
                            },
                            {
                                label: '文件'
                            },
                            {
                                label: '视频'
                            }
                        ],
                        dataList: [
                            {
                                dataType: require('../assets/images/material01.png'),
                                dataTitle: '如何写出更好的文章题目',
                                date: '03/01',
                                time: '13:23',
                                upload: '彭浩浩'
                            },
                            {
                                dataType: require('../assets/images/material02.png'),
                                dataTitle: '如何写出更好的文章题目',
                                date: '03/01',
                                time: '13:23',
                                upload: '彭浩浩'
                            },
                            {
                                dataType: require('../assets/images/material03.png'),
                                dataTitle: '如何写出更好的文章题目',
                                date: '03/01',
                                time: '13:23',
                                upload: '彭浩浩'
                            }
                        ]
                    }
                ],

                courseMask: false,
                courseFilter: false,
                dataMask: false,
                dataFilter: false,


            };
        },
        created() {
            console.log(this.$store.state.user.id);
            MyCollect(this.$store.state.user.id, "").then(res => {
                console.log(res.data.data)
                this.courseList = res.data.data.list;
            }).catch(err => {
                console.log(err)
            });
            MyMaterial (this.$store.state.user.id).then(res => {
                console.log(res.data.data);
                this.materialsList = res.data.data.dataList;
            }).catch(err => {
                console.log(err)
            });


        },
        methods: {
            getPageHeight() {
                let topHeight = document.getElementsByClassName("vux-slider")[0]
                        .offsetTop,
                    diffHeight = window.screen.height - 44;
                this.$nextTick(() => {
                    this.$refs.cateSwiper.xheight = diffHeight + "px";
                });
            },

            onFilterCourse() {
                this.courseMask = !this.courseMask;
                this.courseFilter = !this.courseFilter
            },
            onFilterData() {
                this.dataMask = !this.dataMask;
                this.dataFilter = !this.dataFilter
            }
        }
    };
</script>

<style lang="less" scoped>
    .myCollect {
        /deep/ .headerBox {
            background-color: #fff;
            border-bottom: 1px solid #eee;

            .vux-header-left {
                left: 24px;

                .vux-header-back {
                    color: #000;
                }

                .left-arrow:before {
                    border-color: #000;
                }
            }

            .vux-header-title {
                color: #000;
                font-size: 30px;
            }
        }

        /* 搜索 */

        .search {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 30px;
            background: #fff;
            z-index: 80;
            position: relative;

            i {
                position: absolute;
                left: 50px;
            }

            input {
                display: inline-block;
                background: #f8f9fa;
                padding: 20px;
                border-radius: 40px;
                padding-left: 80px;
                width: 70%;
                border: 0;
            }

            span {
                font-size: 30px;
                color: #1f7aff;
            }
        }

        /* 筛选按钮 */

        .filterMask {
            position: absolute;
            top: 132px;
            bottom: 0;
            left: 0;
            right: 0;
            background: rgba(0, 0, 0, 0.5);
            z-index: 8;
        }

        .popFilter {
            position: absolute;
            left: 0;
            right: 0;
            background: #fff;
            z-index: 9;
            padding: 20px 30px;

            .filterTitle {
                font-size: 26px;
                color: #626262;
            }

            .filterLabels {
                margin-top: 20px;

                .filterLabel {
                    text-align: center;
                    background: #f1f1f1;
                    font-size: 26px;
                    color: #626262;
                    width: 20%;
                    line-height: 2;
                    display: inline-block;
                    margin-right: 5%;
                    margin-bottom: 20px;
                }

                & > .filterLabel:nth-child(4n) {
                    margin-right: 0;
                }
            }
        }

        // 课程样式
        .courseBox {
            /* 课程 */

            .courseList {
                border-bottom: 20px solid #f8f9fa;

                .delBtn {
                    background-color: #ff9300;
                    color: #fff;
                }

                .shareBtn {
                    background-color: #FE6805;
                    color: #fff;
                }

                .courses {
                    display: flex;
                    // background: #fff;
                    padding: 20px 30px;

                    .leftCont {
                        flex: 0 0 50%;

                        .courseImg {
                            width: 312px;
                            height: 182px;
                            display: block;
                        }
                    }

                    .rightCont {
                        flex: 0 0 50%;
                            overflow: hidden;

                        .contTitle {
                            font-size: 30px;
                            overflow: hidden;
                            text-overflow: ellipsis;
                            white-space: nowrap;
                        }

                        .orderInfo {
                            font-size: 24px;
                            line-height: 2;
                            color: #999;
                            margin-bottom: 40px;
                        }

                        .price {
                            font-size: 34px;
                            color: #f14927;

                            span {
                                font-size: 24px;
                                color: #b48a59;
                            }
                        }
                    }
                }
            }

        }

        .dataBox {
            .dataList {
                display: flex;
                justify-content: space-between;
                align-items: center;
                padding: 30px;
                background: #fff;
                border-bottom: 1px solid #eee;

                .dataLeft {
                    display: flex;
                    align-items: center;

                    img {
                        width: 83px;
                        height: 98px;
                    }

                    .dataInfo {
                        margin-left: 20px;

                        div:first-child {
                            font-size: 30px;
                            color: #505050;
                            margin-bottom: 10px;
                        }

                        div:last-child {
                            font-size: 24px;
                            color: #a1a1a1;

                            .ml_20 {
                                margin-left: 20px;
                            }
                        }
                    }
                }

                .dataRight {
                    img:first-child {
                        width: 38px;
                        height: 31px;
                    }

                    img:nth-child(2) {
                        width: 40px;
                        height: 36px;
                        margin-left: 30px;
                    }

                    img:last-child {
                        width: 36px;
                        height: 32px;
                        margin-left: 30px;
                    }
                }
            }

            .emptyBox {
                position: absolute;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
                width: 300px;
            }
        }
    }
</style>